import pygame
import constants as c
from os import path

class Plane(pygame.sprite.Sprite):
    def __init__(self, img, K_UP, K_DOWN, K_LEFT, K_RIGHT):
        super().__init__()
        self.img1 = pygame.transform.scale(img,(50,36))
        # self.img1 = sleimg.set_colorkey(c.BLACK)
        self.rect = self.img1.get_rect()
        self.rect.centerx = c.WIDTH/2
        self.rect.bottom = c.HEIGHT-10
        self.speed = 5
        self.shield = 100
        self.radius = 20
        self.shoot_delay = 250
        self.last_shoot = pygame.time.get_ticks()
        self.lives = 3
        self.hidden = False
        self.hide_timer = pygame.time.get_ticks()
        self.power = 1
        self.power_timer = pygame.time.get_ticks()
        self.K_UP = K_UP
        self.K_DOWN = K_DOWN
        self.K_LEFT = K_LEFT
        self.K_RIGHT = K_RIGHT

    def hide(self):
        pass

    def update(self):
      if self.power >= 2 and pygame.time.get_ticks() - self.power_timer >= c.POWERTIME:
          self.power -= 1
          self.power_timer = pygame.time.get_ticks()
      if self.hidden and pygame.time.get_ticks() - self.hide_timer >= 1000:
          self.hidden = False
          self.rect.centerx = c.WIDTH/2
          self.rect.bottom = c.HEIGHT - 30

      self.shoot()
      self.move()

    def move(self):
        pass

    def shoot(self):
        now = pygame.time.get_ticks()
        if now - self.last_shoot > self.shoot_delay:
            self.last_shoot = now
            #单火力
            if self.power == 1:
                pass
            if self.power == 2:
                pass
            if self.power == 3:
                pass
    def powerup(self):
        pass


if __name__ =='__main__':
    path_dir = path.dirname(path.dirname(__file__))
    img_dir = path.join(path_dir, 'pic')
    background = pygame.image.load(path.join(img_dir, 'starfield.png'))
    plane = Plane(background, pygame.KEYUP, pygame.KEYDOWN,pygame.K_LEFT, pygame.K_RIGHT)
    plane.shoot()

    plane.update()

